<template>
  <div>
    <el-button type="primary" @click="onSignIn">用户签到</el-button>
    <div>
        <div>
            <span>用户积分：</span>{{ user.userScore }}
        </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { getUserInfo,signIn } from "../api/api";
import { ElMessage } from "element-plus";

const user = ref({
  userScore: 0,
});

//用户签到
const onSignIn = () => {
    signIn().then(res=>{
        if(res.data.code == 200){
            ElMessage.success(res.data.msg);
            user.value = res.data.data;
        }else{
            ElMessage.error(res.data.msg)
        }
    })
}

const loadUserInfo = () => {
  getUserInfo().then((res) => {
    if (res.data.code == 200) {
      user.value = res.data.data;
    }
  });
};

onMounted(() => {
  loadUserInfo();
});
</script>

<style scoped></style>
